package com.ruoyi.web.controller.dmphive;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dmp.hive.config.domain.DmpHiveConfig;
import com.ruoyi.dmp.hive.config.service.IDmpHiveConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * Hive配置Controller
 * 
 * @author MquanZeng
 * @date 2021-12-16
 */
@RestController
@RequestMapping("/dmphive/config")
public class DmpHiveConfigController extends BaseController
{
    @Autowired
    private IDmpHiveConfigService dmpHiveConfigService;

    /**
     * 查询Hive配置列表
     */
    @PreAuthorize("@ss.hasPermi('dmphive:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmpHiveConfig dmpHiveConfig)
    {
        startPage();
        List<DmpHiveConfig> list = dmpHiveConfigService.selectDmpHiveConfigList(dmpHiveConfig);
        return getDataTable(list);
    }

    /**
     * 导出Hive配置列表
     */
    @PreAuthorize("@ss.hasPermi('dmphive:config:export')")
    @Log(title = "Hive配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmpHiveConfig dmpHiveConfig)
    {
        List<DmpHiveConfig> list = dmpHiveConfigService.selectDmpHiveConfigList(dmpHiveConfig);
        ExcelUtil<DmpHiveConfig> util = new ExcelUtil<DmpHiveConfig>(DmpHiveConfig.class);
        util.exportExcel(response, list, "Hive配置数据");
    }

    /**
     * 获取Hive配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('dmphive:config:query')")
    @GetMapping(value = "/{hvcId}")
    public AjaxResult getInfo(@PathVariable("hvcId") Long hvcId)
    {
        return AjaxResult.success(dmpHiveConfigService.selectDmpHiveConfigByHvcId(hvcId));
    }

    /**
     * 新增Hive配置
     */
    @PreAuthorize("@ss.hasPermi('dmphive:config:add')")
    @Log(title = "Hive配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmpHiveConfig dmpHiveConfig)
    {
        return toAjax(dmpHiveConfigService.insertDmpHiveConfig(dmpHiveConfig));
    }

    /**
     * 修改Hive配置
     */
    @PreAuthorize("@ss.hasPermi('dmphive:config:edit')")
    @Log(title = "Hive配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmpHiveConfig dmpHiveConfig)
    {
        return toAjax(dmpHiveConfigService.updateDmpHiveConfig(dmpHiveConfig));
    }

    /**
     * 删除Hive配置
     */
    @PreAuthorize("@ss.hasPermi('dmphive:config:remove')")
    @Log(title = "Hive配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hvcIds}")
    public AjaxResult remove(@PathVariable Long[] hvcIds)
    {
        return toAjax(dmpHiveConfigService.deleteDmpHiveConfigByHvcIds(hvcIds));
    }

    /**
     * 获取Hive连接配置下拉项
     */
    @GetMapping("/selectOptions")
    public AjaxResult selectOptions()
    {
        return AjaxResult.success(dmpHiveConfigService.getSelectOptionsList());
    }
}
